package com.drdj.kitty;

import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class FacebookActivity extends BaseActivity {
	
	private WebView mWebView;
//	private ProgressDialog mProgressDialog;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.facebook_activity);

		setTitle("Facebook");

		setAsMenu();

		mWebView = (WebView) findViewById(R.id.wbEmail);
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.setVerticalScrollbarOverlay(true);
		mWebView.loadUrl("http://m.facebook.com/kittycastlekr");
		mWebView.setWebViewClient(new WebViewClient() {
			@Override
			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(url);
				return true;
			}
			
			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
				setTitle("Loading...");
//				if (mProgressDialog == null) {
//					mProgressDialog = new ProgressDialog(TwitterActivity.this);
//					mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//					mProgressDialog.setTitle("Web Page Loading");
//					mProgressDialog.setMessage("Loading...");
//				}
//
//				if (!mWebView.canGoBack()) {
//					mProgressDialog.show();
//				}
			}
			
			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				setTitle("Facebook");
//				if (mProgressDialog != null && mProgressDialog.isShowing()) {
//					mProgressDialog.dismiss();
//				}
			}
		});
		mWebView.getSettings().setSupportZoom(false);

		mWebView.setWebChromeClient(new WebChromeClient() {
			@Override
			public boolean onJsAlert(WebView view, String url, String message,
					final android.webkit.JsResult result) {
				new AlertDialog.Builder(FacebookActivity.this)
						.setTitle("AlertDialog")
						.setMessage(message)
						.setPositiveButton(android.R.string.ok,
							new AlertDialog.OnClickListener() {
								public void onClick(DialogInterface dialog,	int which) {
									result.confirm();
								}
							}
						).setCancelable(false).create().show();

				return true;
			};
		});
	}

	@Override
	public void onBackPressed() {
		if (mWebView.canGoBack()) {
			mWebView.goBack();
		} else {
			super.onBackPressed();
		}
	}
	
//	@Override
//	protected void onResume() {
//		Log.d("asd", "onresume");
//		webView.reload();
//		super.onResume();
//	}
}